<template>
  <BaseMainSlot>
    <template v-slot:searchbox>
      <el-collapse v-model="activeName" accordion @change="handleChange">
        <el-collapse-item name="1">
          <template slot="title">
            <div class="select-btns search-btns" @click.stop="changeSelect()">
              <i class="el-icon-circle-check"></i>
              <p v-if="activeName === '1'">收起筛选</p>
              <p v-if="activeName === ''">展开筛选</p>
            </div>
          </template>
          <div class="search-btn search-btns" @click.stop="queryPageList()">
            <i class="el-icon-circle-check"></i>
            <p>查询</p>
          </div>
          <!-- <div class="select-box-content">
            <div class="select-box-content-name">批次编号</div>
            <el-input v-model="mnecode" clearable />
          </div> -->
          <div class="select-box-content">
            <div class="select-box-content-name">物料名称</div>
            <el-select filterable clearable v-model="materialId" >
              <el-option v-for="(item, index) in materialList" :key="index" :label="item.name" :value="item.materialId" />
            </el-select>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">投入鱼塘</div>
            <el-select filterable clearable v-model="fishPondId" >
              <el-option v-for="(item, index) in pondList" :key="index" :label="item.pondName" :value="item.fishPondId" />
            </el-select>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">作业人</div>
            <el-select filterable clearable v-model="staffName" >
              <el-option v-for="(item, index) in staffList" :key="index" :label="item.staffName"
                :value="item.staffName" />
            </el-select>
          </div>
          <div class="select-box-content">
            <div class="select-box-content-name">作业日期</div>
            <el-date-picker v-model="inputDate" type="date" placeholder="选择日期" value-format="yyyy-MM-dd" clearable />
          </div>
        </el-collapse-item>
      </el-collapse>
    </template>
    <template v-slot:btnsBar>
      <OperationBar :categoryList="operationList" @categoryBar="operationChange" />
    </template>
    <template v-slot:categoryBox>
      <CategoryBar :categoryList="categoryList" @categoryBar="categoryBar" />
    </template>
    <template v-slot:content>
      <el-table ref="tableData" v-loading="loading" highlight-current-row :data="tableData" class="margin-top10px" stripe
        border height="calc(100% - 50px)" :row-key="
          row => {
            return row.disinfectWorkId;
          }
        " @selection-change="handleSelectionChange" @select="select" @select-all="selectAll">
        <el-table-column type="selection" :selectable="selectable" width="55" :reserve-selection="true" />
        <el-table-column type="index" label="序号" width="50">
          <template slot-scope="scoped">
            {{ scoped.row.disinfectWorkId ? scoped.$index + 1 : '' }}
          </template>
        </el-table-column>
        <!-- <el-table-column prop="productionBatchCode" label="物料名称" /> -->
        <!-- <el-table-column prop="batchName" label="批次编号" /> -->
        <el-table-column prop="pondName" label="鱼塘名称" />
        <el-table-column prop="staffName" label="作业人" />
        <el-table-column prop="workDateTime" label="作业日期" />
        <!-- <el-table-column prop="overdueDateTime" label="逾期日期" /> -->
        <!-- <el-table-column width="120" label="操作">
          <template v-if="scope.row.disinfectWorkId" slot-scope="scope">
            <el-button class="text-btn-cursor" type="text" size="small" @click="edit(scope.row)">修改
            </el-button>
          </template>
        </el-table-column> -->
      </el-table>
      <Pagination :page-size="pageSize" :current-page="currentPage" :total-size="totalSize"
        @changeCurrentPage="changeCurrentPage" />
    </template>
  </BaseMainSlot>
</template>

<script>
import ActionBar from "@/components/ActionBar";
import Pagination from "@/components/Pagination";
import CategoryBar from "@/components/CategoryBar";
import OperationBar from "./components/CategoryBar.vue";
import BaseMainSlot from "@/components/BaseMainSlot/kong-new.vue";
import { mymixin } from "@/utils/mixin";
import { mapGetters } from 'vuex';

import DisinfectionOperationApi from "@/api/operation-management/disinfection-operation"
import BatchMangeApi from "@/api/batch-mange"
import EnumApi from "@/api/enum"
import MaterialApi from "@/api/basic-info-manage/material"
import FishPondApi from "@/api/basic-info-manage/fishPond"
import StaffApi from "@/api/basic-info-manage/staff";
export default {
  name: 'WaterChangeOperation',
  components: { ActionBar, Pagination, BaseMainSlot, CategoryBar, OperationBar },
  mixins: [mymixin],
  data () {
    return {
      mnecode: "",//批次编号
      fishPondId: "",//养殖鱼塘ID
      materialId: '',//作业人
      staffName: '',//作业人
      inputDate: "",//作业日期
      checkedIdList: [],
      pondList: [],//全部鱼塘
      batchList: [],//全部未完成批次
      FishVarietyData: [],//全部品种
      staffList: [],//全部员工/作业人
      materialList: [],//物料
      //分类列表
      categoryList: [
        // {id:0,mark:'audit',name:"待审核",value:false},
        // {id:1,mark:'audit',name:"已审核",value:true},
        // {id:2,mark:'success',name:"审核通过",value:true},
        // {id:3,mark:'success',name:"审核未通过",value:false},
      ],
      //分类列表
      operationList: [
        // {id:0,mark:'router',name:"换水作业",value:"/water-change-operation-history"},
        // {id:1,mark:'router',name:"消毒作业",value:"/disinfection-operation-history"},
        { id: 1, mark: 'router', name: "吊网作业", value: "/hanging-operation-history" },
        { id: 2, mark: 'router', name: "露网作业", value: "/dew-net-operation-history" },
        { id: 3, mark: 'router', name: "投喂作业", value: "/feeding-operation-history" },
      ],
      showAddEditDialog: false,
      // activeName: '1',//控制是否默认展开
    };
  },
  computed: {
    ...mapGetters({
      judgePermission: "permission/judgePermission"
    })
  },
  watch: {},
  created () { },
  mounted () {
    this.queryEnumList()
    this.queryFishPond()
    this.queryBatchMange()
    this.queryStaff()
    this.queryMaterial()
  },
  methods: {
    categoryBar (item) {
      this.audit = ''
      this.success = ''
      if (item.mark === 'audit') this.audit = item.value;
      if (item.mark === 'success') {
        this.audit = true
        this.success = item.value;
      }
    },
    operationChange (item) {
      this.$router.push({ path: item.value })
    },
    //查询枚举
    queryEnumList () {
      EnumApi.list({ enumType: 'AuditType' }).then(res => {
        if (res.data) {
          res.data.forEach((item, index) => {
            this.categoryList.push({
              id: index,
              mark: item.name,
              name: item.value
            })
          })
        }
        console.log(this.categoryList, this.categoryList)
      })
    },
    //查询可选批次
    queryBatchMange () {
      BatchMangeApi.queryByCondition({ status: 'UN_COMPLETE' }).then(res => {
        this.batchList = res.data;
      })
    },
    //查询可选物料
    queryMaterial () {
      MaterialApi.queryByCondition().then(res => {
        this.materialList = res.data;
      })
    },
    //查询可选鱼塘
    queryFishPond () {
      FishPondApi.queryByCondition().then(res => {
        this.pondList = res.data;
      })
    },
    //查询作业人
    queryStaff () {
      StaffApi.queryByCondition().then(res => {
        this.staffList = res.data;
      })
    },
    // queryPageList() {
    //   let params = {
    //     page: this.currentPage,
    //     size: this.pageSize,
    //     entity: {}
    //   };
    //   if (this.audit !== '') params.entity.audit = this.audit;
    //   if (this.success !== '') params.entity.success = this.success;
    //   if (this.mnecode) params.entity.mnecode = this.mnecode;
    //   if (this.fishPondId) params.entity.fishPondId = this.fishPondId;
    //   if (this.staffName) params.entity.staffName = this.staffName;
    //   if (this.inputDate) params.entity.inputDate = this.inputDate;
    //   DisinfectionOperationApi.queryPageByCondition(params).then(res => {
    //     if (res.success === true) {
    //       let data = res.data || {};
    //       this.totalSize = data.totalElements;
    //       // 赋值数组
    //       this.tableData = data.content;
    //       this.addblankmet();
    //       this.resetActionBar();
    //     }
    //   });
    // },
    changeCurrentPage (currentPage) {
      this.currentPage = currentPage;
      ;
    },
    selectAll (list) {
      let notvalue = true
      list.forEach(item => {
        if (!item.disinfectWorkId) {
          notvalue = false
        }
      });
      if (notvalue === false) {
        this.$message.warning("不可选择空数据！");
      }
    },
    select (list) {
      let notvalue = true
      list.forEach(item => {
        if (!item.disinfectWorkId) {
          notvalue = false
        }
      });
      if (notvalue === false) {
        this.$message.warning("不可选择空数据！");
      }
    },
    // 表格删除
    delmessage () {
      DisinfectionOperationApi.delListById({ idList: this.checkedIdList }).then(res => {
        if (res.success) {
          ;
          this.$message.success("删除成功");
          this.resetActionBar();
        }
      });
    },
    handleSelectionChange (list) {
      this.checkedIdList = [];
      let notvalue = true
      let emptyList = []
      this.checkedIdList = list.map(item => {
        if (item.disinfectWorkId) {
          return item.disinfectWorkId
        } else {
          notvalue = false
          emptyList.push(item)
          return ""
        }
      });
      if (notvalue === false) {
        // this.$message.warning("不可选择空数据！");
        this.toggleNoSelection(emptyList)
        return
      }
      if (this.checkedIdList.length >= 1) this.delActive = true;
      else this.delActive = false;
    },
    // 单个删除
    delOne (row) {
      this.$confirm("此操作将永久删除该项, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        
      })
        .then(() => {
          DisinfectionOperationApi.delById({ id: row.disinfectWorkId }).then(res => {
            if (res.success === true) {
              this.$message.success("删除成功!");
              ;
              this.resetActionBar();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 添加
    add () {
      this.nowChanceStau = 'add'
      this.titleText = "添加"
      this.addActive = false;
      this.delActive = false;
      this.showAddEditDialog = true
    },
    // 修改
    edit (row) {
      if (row.disinfectWorkId) {
        this.editObject = JSON.parse(JSON.stringify(row));
        this.nowChanceStau = 'edit'
        this.titleText = "修改"
        this.addActive = false;
        this.delActive = false;
        this.showAddEditDialog = true
      } else {
        this.editObject = {}
      }
    }
  }
};
</script>

<style lang="scss" scoped></style>
